# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: 03-下拉.py
"""
from io import BytesIO

from selenium import webdriver
from selenium.webdriver import ActionChains

browser = webdriver.Chrome()

# driver.get("https://www.1688.com/")
#  一次下拉  直接获取页面高度  然后下拉   X Y 轴
# driver.execute_script("window.scrollTo(0, 11019)")

# 循环下拉



url = 'https://pic.netbian.com/4kmeinv/index.html'
browser.get(url)
# src = browser.find_elements_by_xpath('//ul[@class="clearfix"]/li/a/img')
# for i in src:
#     url = i.get_attribute('src')
#     print(url)

from PIL import Image
img = browser.find_element_by_xpath('//ul[@class="clearfix"]/li[1]/a/img')
location = img.location
size = img.size
top, bottom, left, right = location['y'], location['y'] + size['height'], location['x'], location['x'] + size['width']
print(top, bottom, left, right)
screen = browser.get_screenshot_as_png()
screen = Image.open(BytesIO(screen))
cap = screen.crop((left, top, right, bottom))
cap.save('asas.png')
